/**
 * @program: LeetCode
 * @description: LeetCode : 376. 摆动序列
 * @author: WXY
 * @create: 2023-01-20 10:31
 * @Version 1.0
 **/
public class Num376_wiggleMaxLength {
    public static int wiggleMaxLength(int[] nums) {
        int ans = 1;
        int curDiff = 0;
        int preDiff = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            curDiff = nums[i + 1] - nums[i];
            if ((preDiff >= 0 && curDiff < 0) || (preDiff <= 0 && curDiff > 0)) {
                ans++;
                preDiff = curDiff;
            }
        }
        return ans;
    }
    public static int wiggleMaxLength1(int[] nums) {
       if (nums.length == 0) return 0;
        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        int max = dp[0];
        for (int i = 1; i < nums.length; i++) {
            dp[i] = Math.max(dp[i - 1] + nums[i], nums[i]);
            max = Math.max(max, dp[i]);
        }
        return max;
    }
}
